package material.observer;

/**
 * 布告板--当前天气状况的布告板
 * 把最近的温度湿度显示出来
 */
public class CurrentConditionDisplay implements Observer, DisplayElement {
    private float tempature;//温度
    private float humidity;//湿度
    private Subject weatherData;//由于此布告板实现了Observer接口，所以可以从WeatherData中获取改变

    public CurrentConditionDisplay(Subject weatherData) {
        this.weatherData = weatherData;
        weatherData.registerObserver(this);//构造函数首先将自身添加到观察者行列中
    }

    @Override
    public void display() {
        System.out.println("当前温度：【" + this.tempature + "F degree】\n当前湿度：【" + this.humidity + "% humidity】");
    }

    @Override
    public void update(float temp, float humidity, float pressure) {
        this.tempature = temp;
        this.humidity = humidity;
        this.display();
    }
}
